# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=amass
pkgver=v5.0.1.r1.g61f53cc
pkgrel=1
epoch=3
pkgdesc='In-depth subdomain enumeration written in Go.'
arch=('x86_64' 'aarch64')
groups=('blackarch' 'blackarch-scanner' 'blackarch-recon')
url='https://github.com/OWASP/Amass'
license=('Apache-2.0')
makedepends=('git' 'go')
source=("$pkgname::git+https://github.com/OWASP/Amass.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null |
      sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "%s.%s" "$(git rev-list --count HEAD)" \
      "$(git rev-parse --short=7 HEAD)"
  )
}

build() {
  cd $pkgname

  export CGO_ENABLED=0

  GOPATH="$srcdir" go mod download
  GOPATH="$srcdir" go build \
    -trimpath \
    -buildmode=pie \
    -mod=readonly \
    -modcacherw \
    -ldflags "-s -w" \
    -o $pkgname "./cmd/$pkgname"
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/share/$pkgname"

  install -Dm 755 $pkgname "$pkgdir/usr/bin/$pkgname"

  cp -a --no-preserve=ownership resources "$pkgdir/usr/share/$pkgname//"
  chmod 644 "$pkgdir/usr/share/$pkgname/resources/"*

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" *.md
}

